#define NOODIRECT
#include "../Buffer/Buffer.cpp"
#include <UnitTest++.h>
#include <stdio.h>

SUITE(BufferTests) {

	TEST(Constructor) {
		Buffer buffer;
		char input[] = "./testinput.txt";
		char output[] = "./testoutput.txt";
		bool result = buffer.init(input, output);
		CHECK(result == true);
	}

	TEST(GetChar) {
		Buffer buffer;
		char input[] = "./testinput.txt";
		char output[] = "./testoutput.txt";
		buffer.init(input, output);
		char c = buffer.getChar();
		CHECK(c == 't');
		c = buffer.getChar();
		CHECK(c == 'e');
		c = buffer.getChar();
		CHECK(c == 's');
		c = buffer.getChar();
		CHECK(c == 't');
	}

	TEST(UngetChar){
		Buffer buffer;
		char input[] = "./testinput.txt";
		char output[] = "./testoutput.txt";
		buffer.init(input, output);
		for(int i = 0; i < 4; i++) {
			buffer.getChar();
		}

		if(buffer.ungetChar(4) != 0) {
			puts("unget buffer failed!");
		}

		char c = buffer.getChar();
		CHECK(c == 't');
		c = buffer.getChar();
		CHECK(c == 'e');
		c = buffer.getChar();
		CHECK(c == 's');
		c = buffer.getChar();
		CHECK(c == 't');
	}

	TEST(WriteString) {
		Buffer buffer;
		char input[] = "./testinput.txt";
		char output[] = "./testoutput1.txt";
		buffer.init(input, output);
		buffer.writeString("Output Test 1\n");
	}

	TEST(CopyString) {
		Buffer buffer;
		char input[] = "./testinput.txt";
		char output[] = "./testoutput.txt";
		buffer.init(input, output);
		for(int i = 0; i < 4; i++) {
			buffer.getChar();
		}
		char lexemStorage[6];
		buffer.copyString(4, &lexemStorage[0]);
		CHECK(lexemStorage[0] == 4);
		CHECK(lexemStorage[1] == 't');
		CHECK(lexemStorage[2] == 'e');
		CHECK(lexemStorage[3] == 's');
		CHECK(lexemStorage[4] == 't');
		CHECK(lexemStorage[5] == '\0');
	}

	TEST(BigDataBigSteps) {
		Buffer buffer;
		char input[] = "./testinput.txt";
		char output[] = "./testoutput2.txt";
		buffer.init(input, output);
		char c[1000001];
		for(int i = 0; i < 1000000; i++){
			c[i] = buffer.getChar();
		}
		c[1000000] = '\0';
		buffer.writeString(c);

	}

	TEST(BigDataSmallSteps) {
		Buffer buffer;
		char input[] = "./testinput.txt";
		char output[] = "./testoutput3.txt";
		buffer.init(input, output);
		char c[2];
		for(int i = 0; i < 1000000; i++){
			c[0] = buffer.getChar();
			c[1] = '\0';
			buffer.writeString(c);
		}
	}

}
